

var DN_CMD = require("zjhCMD");
cc.Class({
    extends: cc.Component,

    properties: {
        className:"confirmroom",
        title:{
            default:null,
            type:cc.Label,
        },
        title:{
            default:null,
            type:cc.Label,
        },
        maxScore:{
            default:null,
            type:cc.Label,
        },
        totaljushu:{
            default:null,
            type:cc.Label,
        },
        content:{
            default:null,
            type:cc.Component,
        },
        citem:{
            default:null,
            type:cc.Node,
        },
    },

    // LIFE-CYCLE CALLBACKS:
    /*
    //返回获取桌子信息  1671
    message GetDeskInfoRsp{
        optional int32 desk_id = 1;     //桌子ID
        optional int32 uin = 2;         //自己的uid
        optional int32 err_no = 3;      // 错误码 1是没找到房间  0是正确
        optional int32 room_id = 4;                     //房间类型主类  1斗牛(30101)  2扎金花(30201)...
        
        // 以下是牛牛的信息
        optional int32 room_type_sub2 = 5;              //房间类型  1.牛牛上庄  2.固定庄家  3.自由抢庄 4.名牌抢庄  5通比牛牛
        optional int32 base_chip = 6;                   // 底分
        optional int32 rule_type = 7;                   // 规则类型 1:牛牛3倍 牛九2倍 牛八2倍   2:牛牛4倍 牛九3倍 牛八牛七2倍
        optional int32 play_count = 8;                  //玩的局数
        repeated int32 bet_type = 9;                    // 加注倍数 是个列表
        
        repeated string nick_list = 10;                     //当前参与玩家的昵称列表
        
        //以下是炸金花信息
        optional int32 gold_base_chip = 11;             //炸金花比分
        repeated int32 gold_score_list = 12;            //下注列表
        optional int32 look_card_limit = 13;            //看牌限制
        optional int32 compare_limit = 14;              //比牌限制
        optional int32 gold_play_count = 15;            //玩的局数
        optional int32 score_limit = 16;
    }
    */
    onLoad: function () {
        this.node.thisJS = this;    
        EventManager.addEventObeserveF(EventConfig.showRoomInfo, handler(this,
            this.showRoomInfo),"confirmroom");    
    },
    
    
    showRoomInfo:function(info){
        if(info.err_no == 1){
            return ;
        }
        this.title.string = "您的ID:" + info.uin ;
        var shareContent = "";
        var resultInfo = [] ;

        var tempInfo = {};
        tempInfo.title = "底分";
        tempInfo.content = info["gold_base_chip"] +"分";
        resultInfo.push(tempInfo);

        var tempInfo = {};
        tempInfo.title = "叫分列表";
        tempInfo.content  = "";
        for(var i=0;i<info["gold_score_list"].length;i++){
            tempInfo.content = tempInfo.content + info["gold_score_list"][i];
            if(i<info["gold_score_list"].length-1){
                tempInfo.content = tempInfo.content + "," 
            }
        }
        GameData.gold_score_list = info["gold_score_list"] ;
        
        resultInfo.push(tempInfo);

        var tempInfo = {};
        tempInfo.title = "看牌限制";
        if(info["look_card_limit"]==0){
            tempInfo.content = "无"
        }else{
            tempInfo.content = info["look_card_limit"] +"分";
        }
        resultInfo.push(tempInfo);


        var tempInfo = {};
        tempInfo.title = "比牌限制";
        if(info["compare_limit"]==0){
            tempInfo.content = "无"
        }else{
            tempInfo.content = info["compare_limit"] +"分";
        }
        resultInfo.push(tempInfo);

        var tempInfo = {};
        tempInfo.title = "局数";
      //  var tempArr = ["","10","20"];
        tempInfo.content = info["gold_play_count"]+"局";
        resultInfo.push(tempInfo);


        var tempInfo = {};
        tempInfo.title = "比分上限";
        if(info["score_limit"]==0){
            tempInfo.content = "无"
        }else{
            tempInfo.content = info["score_limit"] +"分";
        }
        resultInfo.push(tempInfo);



        for (i=0;i<resultInfo.length;i++){
            var item = cc.instantiate(this.citem);
            var itemtitle = cc.find("title",item);
            var itemcontent = cc.find("content",item);
            itemtitle.getComponent(cc.Label).string = resultInfo[i].title ;
            itemcontent.getComponent(cc.Label).string = resultInfo[i].content ;
            shareContent = shareContent + resultInfo[i].title + ":" + resultInfo[i].content ;
            if(i<resultInfo.length-1){
                shareContent = shareContent + ",";
            }
            this.content.node.addChild(item)
        }


        var tempInfo = {deskid:GameData.deskid,
              gameid:100002, };
        var infoString = require("AES").encrypt(JSON.stringify(tempInfo))
        console.log(infoString);
        console.log("解析加mi");
        console.log(require("AES").decrypt(infoString));
        dump(JSON.parse(require("AES").decrypt(infoString)));
        var href = window.location.href, base = href;
        var lastpt = href.lastIndexOf("?");
        var last = href.lastIndexOf("/");
        if (last != -1 && lastpt > last)
            base = base.substr(0, lastpt);
        console.log("###############->"+base+"?info="+infoString);
       
        window.shareData = {
            "link":base+"?info="+infoString,
            "desc":shareContent,
            "title":UserInfoModel.info.nick+"邀请你玩游戏",
        };
    },
    //加入
    jiaruRoom:function(){
        if(GameData.deskid){
           GameNet.sendRequest({cmd:DN_CMD.UserEnterDeskReq,
              body:{ 
              desk_id:GameData.deskid,
              enter_type:0,
                  callback:function(info){
              Log.logd("readyReq收到回调");
          }}});
        }
        this.node.active = false ;
    },
    //观战
    guanzhanRoom:function(){
        if(GameData.deskid){
           GameNet.sendRequest({cmd:DN_CMD.UserEnterDeskReq,
              body:{ 
              desk_id:GameData.deskid,
              enter_type:1,
                  callback:function(info){
              Log.logd("readyReq收到回调");
          }}});
        }
        this.node.active = false ;
    },
});